<template>
	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true"><block slot="backText"></block>
			<block slot="content">二维码</block>
		</cu-custom>
		<view v-if="!state.autor.client.dflg && !outTime" class="container">
			<uqrcode class="flex justify-center" ref="uqrcode"></uqrcode>
		</view>
		<view v-else-if="state.autor.client.dflg" class="padding margin text-center">
			<view>
				<text class="text-red text-xxl">当前用户(ID:{{state.autor.client.clientId}})处于冻结状态</text>
			</view>
			<view>
				<text class="text-red text-xxl">请联系客服明确原因</text>
			</view>
			<view>
				<text @tap="phoneCall" class="text-blue text-xxl">联系电话：{{state.autor.store.conTel}}</text>
			</view>
		</view>
		<view v-else-if="outTime" class="padding margin text-center">
			<view>
				<text class="text-red text-xxl">二维码已过期</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad: function(){
			this.state = this.common.getState();
		},
		data: function() {
			return {
				state: {},
				codeStr: "",
				outTime:false,
			};
		},
		onShow: function() {
			this.state = this.common.getState();
		},
		onReady:function() {
			if (!this.state.autor.client.dflg) {
				this.init();
			}
		},
		methods: {
			init: function() {
				let self = this;
				console.log(this.state.autor);
				this.http.get({
					url: "/client/qCode",
					param : {
						storeId: this.state.autor.store.storeId,
						clientId: this.state.autor.client.clientId
					}
				}).then(function(res) {
					let codeStr = JSON.stringify(res);
					self.$refs
						.uqrcode
						.make({
							mode: "view",
							size: 300,
							text: codeStr
						});
						let timerId = setTimeout(function() {
							let currentPage = getCurrentPages();
							if(1 <currentPage.length ){
								uni.navigateBack();
							}else{
								self.outTime = true;
							}
						}, 5000);
				}).catch(function(code) {
					if ("PAY_ORDER" === code) {
						uni.navigateTo({
							url: "../pages/orders"
						});
					} else if ("PAY_DEPOSIT" === code) {
						uni.navigateTo({
							url: "../pages/deposits"
						});
					}
				});
			}
		}

	}
</script>

<style scoped>
	.uqrcode {
		display: flex;
		justify-content: center;
	}
	.container {
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		position: absolute;
		top: 0;
	}
</style>
